/**
 * Created by lenovo on 2017/5/8.
 * 组件1：StorePageStore.react.js（门店数据组件）
 * 组件2：StorePageMessage.react.js（门店详细信息组件）
 */
import React from 'react';
import StorePageStore from './storePageStore.react';
import StorePageMessage from './storePageMessage.react';

class storePageHeader extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            headerData: '',
            storePageStoreData: {
                //门店图片url
                storeUrl: '',
                //门店名称
                storeName: '',
                //星级评价
                storeStars: '',
                //营业时间
                storeTime: ''
            },
            storeMessage: {
                storeAddress: '',
                storeTelephone: ''
            }
        }
    }

    componentDidMount() {

    }

    componentWillReceiveProps(nextProps) {
        //数据加载
        const headerData = nextProps.headerData;
        if (headerData !== undefined || headerData !== '') {
            this.setState({
                headerData: headerData,
                storeMessage: {
                    storeAddress: headerData.address,
                    storeTelephone: headerData.telephone
                }
            });
            if (headerData.shop_info !== undefined && headerData.shop_info.hasOwnProperty('time')) {
                this.setState({
                    storePageStoreData: {
                        //门店图片url
                        storeUrl: headerData.brand_logo_url,
                        //门店名称
                        storeName: headerData.name,
                        //星级评价
                        storeStars: headerData.stars,
                        //营业时间
                        storeTime: headerData.shop_info.time
                    }
                });
            } else {
                this.setState({
                    storePageStoreData: {
                        //门店图片url
                        storeUrl: headerData.brand_logo_url,
                        //门店名称
                        storeName: headerData.name,
                        //星级评价
                        storeStars: headerData.stars,
                        //营业时间
                        storeTime: '暂无'
                    }
                });
            }
        }
    }

    render() {
        /*开发数据*/

        return (
            <div className="">
                {/*<header className="headerContainer">
                    <span className="headerName">门店</span>
                </header>*/}
                <div className="storeMessageContainer">
                    <StorePageStore storePageStoreData={this.state.storePageStoreData}/>
                    <StorePageMessage storeMessage={this.state.storeMessage}/>
                </div>
            </div>
        );
    }
}

export default storePageHeader;